﻿@model IEnumerable<Mvc4.Models.EpisodeModel>

@{
    ViewBag.Title = "Index";
    var shows =(IEnumerable<SelectListItem>) ViewBag.ShowSelect;
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<div id="actions">
<select>
<option>More</option>

</select>
</div>
<div>Page @(ViewBag.Page) of @(ViewBag.Pages) @if (ViewBag.Page > 1)
                                                  {
                                                      @Html.ActionLink("Prev",MVC.Episode.Index((int)(ViewBag.Page-1),(int)ViewBag.PageSize))
                                                  } @if (ViewBag.Page < ViewBag.Pages) 
                                                  {
                                                      @Html.ActionLink("Next",MVC.Episode.Index((int)(ViewBag.Page+1),(int)ViewBag.PageSize))
                                                  }</div>
<table>
<thead>
    <tr>
    <th><input type="checkbox" data-role="SelectAll" /></th>
        <th>
            @Html.DisplayNameFor(model => model.ShowID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.LastWatched)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.EpisodeName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.EpisodeNumber)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Season)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Path)
        </th>
        <th></th>
    </tr>
</thead>
<tbody>
@foreach (var item in Model) {
    <tr>
        <td>
            <input type="checkbox" data-role="selector" value="@item.EpisodeID" />
        </td>
        <td>
            @Html.ActionLink(shows.First(s => s.Value == item.ShowID.ToString()).Text, MVC.Show.Details(item.ShowID), htmlAttributes: new { title = item.ShowID.ToString() })
        </td>
        <td>
            @Html.DisplayFor(m => item.LastWatched)
        </td>
        <td>
            @Html.DisplayFor(m => item.EpisodeName)
        </td>
        <td>
            @Html.DisplayFor(m => item.EpisodeNumber)
        </td>
        <td>
            @Html.DisplayFor(m => item.Season)
        </td>
        <td>
            @Html.DisplayFor(m => item.Path)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.EpisodeID }) |
            @Html.ActionLink("Details", "Details", new { id=item.EpisodeID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.EpisodeID })
        </td>
    </tr>
}
</tbody>
</table>
@section scripts{
<script type="text/javascript">
    $(document).ready(function () {
        var selectorBox = $('thead input::checkbox[data-role="SelectAll"]');
        selectorBox.on('click', function () {
            var isChecked = $(this).attr('checked') === 'checked';
            $('tbody ::checkbox[data-role="selector"]').prop('checked', isChecked);
        });
        var actionSection = $('#actions');
        var select = $('select option', actionSection).slice(1);
    });

</script>

}